package com.game.worm.mobile.view.http;

import com.dx.as.common.JWResult;
import com.dx.as.http.HttpClientHelper;
import com.dx.as.http.IHttpListener;
import com.game.worm.mobile.bean.GameBean;
import com.game.worm.mobile.view.home.HomeInfo;
import com.game.worm.mobile.view.tags.bean.TagBean;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

import java.util.List;

import retrofit2.Call;

/**
 * Created by d_xxiang on 2018/3/29.
 */

public class HttpHelper {

    private final static Gson gson = new Gson();
    private static IHttpServices http;
    private static IHttpServices getHttpSevices(){
        if (http == null){
            http = HttpClientHelper.getRetrofit().create(IHttpServices.class);
        }
        return http;
    }

    public static int getHomeInfo(IHttpListener listener){
        Call call = getHttpSevices().doGet(IHttpServices.home);
        HttpClientHelper.doNet(call,listener,new TypeToken<JWResult<HomeInfo>>(){});
        return call.hashCode();
    }

    public static int getGameDetials(String appId,IHttpListener listener){
        Call call = getHttpSevices().doGet(IHttpServices.details+appId);
        HttpClientHelper.doNet(call,listener,new TypeToken<JWResult<GameBean>>(){});
        return call.hashCode();
    }

    public static int getTagGameList(String tag,int type,int page ,IHttpListener listener){
        Call call = getHttpSevices().doGet(IHttpServices.tagGameList+tag+"/"+type+"/"+page);
        HttpClientHelper.doNet(call,listener,new TypeToken<JWResult<List<GameBean>>>(){});
        return call.hashCode();
    }

    public static int getTypeGameList(String gameType,int type,int page ,IHttpListener listener){
        Call call = getHttpSevices().doGet(IHttpServices.typeGameList+gameType+"/"+type+"/"+page);
        HttpClientHelper.doNet(call,listener,new TypeToken<JWResult<List<GameBean>>>(){});
        return call.hashCode();
    }

    public static int getHostList(int page ,IHttpListener listener){
        Call call = getHttpSevices().doGet(IHttpServices.hotList+page);
        HttpClientHelper.doNet(call,listener,new TypeToken<JWResult<List<GameBean>>>(){});
        return call.hashCode();
    }

    public static int getNewList(int page ,IHttpListener listener){
        Call call = getHttpSevices().doGet(IHttpServices.newList+page);
        HttpClientHelper.doNet(call,listener,new TypeToken<JWResult<List<GameBean>>>(){});
        return call.hashCode();
    }

    public static int getSingleList(int page ,IHttpListener listener){
        Call call = getHttpSevices().doGet(IHttpServices.singleList+page);
        HttpClientHelper.doNet(call,listener,new TypeToken<JWResult<List<GameBean>>>(){});
        return call.hashCode();
    }

    public static int getWebList(int page ,IHttpListener listener){
        Call call = getHttpSevices().doGet(IHttpServices.webList+page);
        HttpClientHelper.doNet(call,listener,new TypeToken<JWResult<List<GameBean>>>(){});
        return call.hashCode();
    }


    public static int getTagsList(IHttpListener listener){
        Call call = getHttpSevices().doGet(IHttpServices.tags);
        HttpClientHelper.doNet(call,listener,new TypeToken<JWResult<List<TagBean>>>(){});
        return call.hashCode();
    }
//    public static int getAccountInfo(IHttpListener listener){
//        Call call = getHttpSevices().getAccountInfo(IHttpServices.account);
//        HttpClientHelper.doNet(call,listener,new TypeToken<JWResult<AccountBean>>(){});
//        return call.hashCode();
//    }

//    public static int doLogin(Map<String,Object> param,IHttpListener listener){
//        String jsonStr = gson.toJson(param);
//        RequestBody body = RequestBody.create(okhttp3.MediaType.parse("application/json; charset=utf-8"),jsonStr);
//        Call call = getHttpSevices().postLogin(IHttpServices.login,body);
//        HttpClientHelper.doNet(call,listener,new TypeToken<JWResult<Map<String,String>>>(){});
//        return call.hashCode();
//    }
}
